import React from 'react'
import {useRequest} from 'ahooks'
import Mock from 'mockjs'

// 请求 hooks
// 1. state loading error 
// 2. axios 请求 mock.js
// 3. 分页

function App(){
    // hooks
    const getUsername=()=>{
        return new Promise((res,rej)=>{
            setTimeout(()=>{
                res(Mock.mock('@ctitle(5)'))
            },2000)
        })
    }
    const {data,error,loading}=useRequest(getUsername);

    return (
        <>
            {error && <div>failed to load</div>}
            {loading ? <div>loading</div> : <div>username:{data}</div>}
        </>
    )
}

export default App